#!/usr/bin/env python

from scapy.all import *
from time import time

def enviar(ip, interfaz):
	a = ARP()
	a.pdst = ip
	a.hwdst = "ff:ff:ff:ff:ff:ff"
	
	response = sr1(a, iface=interfaz)
	
	return response.summary()

def run(ip, inter):
	t0 = time()
	arp = enviar(ip, inter)
	t1 = time()

	print arp
	print (t1-t0)*(10**3), "ms"

def escuchar(tout, inter):
	sniff(prn = procesador_de_paquetes, filter="arp", timeout=tout, iface=inter)
	
def procesador_de_paquetes(p):
	if ARP in p:
		print p.summary()
		hwsrc = p[ARP].hwsrc
		print "hsaddr: ", hwsrc, " , vendor: ", get_vendor(hwsrc)
		print "[mensaje] de: " + p[ARP].psrc + " a: " + p[ARP].pdst
	
def get_vendor(hwsrc):
	f = open("oui.txt")
	for l in f:
		if len(l.split()) >= 3:
			maskara = l.split()[0][0:8].replace("-", "").lower()
			if maskara == hwsrc[0:8].replace(":", "").lower():
				return " ".join(l.strip().split()[2:])
				
				
